﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace SH.Common.Helper
{
    /// <summary>
    /// MD5帮助类
    /// </summary>
    public static class MD5Helper
    {
        /// <summary>
        /// 获取MD5处理的字符串
        /// </summary>
        /// <param name="pwd">要处理的字符串</param>
        /// <returns>MD5处理后的字符串</returns>
        /// <exception cref="ArgumentException"></exception>
        public static string GetMD5String(string? pwd)
        {
            if (string.IsNullOrEmpty(pwd))
            {
                throw new ArgumentException("参数不能为空！");
            }
            var md5 = MD5.Create();
            byte[] bytes = Encoding.UTF8.GetBytes(pwd);
            byte[] hash = md5.ComputeHash(bytes);
            string hashString = BitConverter.ToString(hash, 0, 12);
            hashString = hashString.Replace("-", "");
            return hashString;
        }
    }
}
